<?php
if (!defined("_INDEX")) { header("Location: /"); die; }

$user_id = $user->getUserId();
$name = trim(UV::readMQ(urldecode(strip_tags($route->POST("name")))));
if (!$user->isUser() && $name == "")
	die("name");
$user_ip = $_SERVER['REMOTE_ADDR'];
$news_id = UV::readInt(strip_tags($route->POST("news_id")));
$parent = UV::readInt(strip_tags($route->POST("parent_id")));
$text = trim(UV::readMQ(urldecode(strip_tags($route->POST("reply")))));
if ($text == "")
	die("text");
$time = time();
$moder = 0;

if ($db->sendQuery("insert into `news_comments` values(NULL,'$user_id','$name','$user_ip','$news_id','$parent','$text','$time','$moder')"))
{
	$comment_id = mysql_insert_id();
	$login = $user->getUserLogin();
	if ($user->isUser())
		$name = $user->getName()." ".$user->getSName();
	$img = drawAva($user_id);
	$reply_time = date("d",$time)." ".$months[date("m",$time)-1]." ".date("H:i",$time);
	echo $response = "{\"comment_id\":\"$comment_id\",\"img\":\"$img\",\"user_id\":\"$user_id\",\"login\":\"$login\",\"name\":\"$name\",\"text\":\"$text\",\"time\":\"$reply_time\"}";
}
else
	echo "erroradding";

?>